package com.meshnetics.gb.stack.mac.type;

import com.meshnetics.gb.type.impl.zcl.Bitmap;

/**
 * TxOptions bitmap used in MACDataRequest.
 *
 * @author AKovylin
 */
public class TxOptions extends Bitmap {
    public TxOptions(boolean acknowledged, boolean gts, boolean indirect, boolean security) {
        this(TypeTxOptions.TYPE, new byte[]{0});
        super.setBit(0, acknowledged);
        super.setBit(1, gts);
        super.setBit(2, indirect);
        super.setBit(3, security);
    }

    public boolean isAcknowledged() {
        return getBit(0);
    }

    public boolean isGts() {
        return getBit(1);
    }

    public boolean isIndirect() {
        return getBit(2);
    }

    public boolean isSecurity() {
        return getBit(3);
    }

    TxOptions(TypeTxOptions type, byte[] value) {
        super(type, value);
        if (value == null) {
            throw new NullPointerException("value is null");
        }
        if (value.length != 1) {
            throw new IllegalArgumentException("invalid value");
        }
        if (getBits(4, 8) > 0) {
            throw new IllegalArgumentException("reserved bits are set");
        }
    }
}
